package br.com.ctm.advogadope.rest.impl;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.PersistenceException;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.jboss.resteasy.annotations.providers.jaxb.Wrapped;

import br.com.ctm.advogadope.model.Usuario;
import br.com.ctm.advogadope.negocio.api.UsuarioNegocio;
import br.com.framework.negocio.exception.NegocioException;

/**
 * @author Cleber
 *
 */
@Path("usuarios")
@Named
public class UsuarioResource extends EntityResourceImpl<Usuario, UsuarioNegocio> {
	

	/* (non-Javadoc)
	 * @see br.com.ctm.advogadope.rest.api.EntityResourceImpl#setNegocio(br.com.framework.negocio.api.BaseNegocio)
	 */
	@Override
	@Inject
	protected void setNegocio(UsuarioNegocio negocio) {
		super.setNegocio(negocio);
	}

	/* (non-Javadoc)
	 * @see br.com.ctm.advogadope.rest.api.EntityResource#findByID(java.lang.Long)
	 */
	@Override
	@GET
	@Path("{id}")
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public Usuario findByID(@PathParam("id") Long id) throws PersistenceException {
		return super.findByID(id);
	}

	/* (non-Javadoc)
	 * @see br.com.ctm.advogadope.rest.api.EntityResource#findAll()
	 */
	@Override
	@GET
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	@Wrapped(element = "usuarios")
	public List<Usuario> findAll() throws PersistenceException {
		return super.findAll();
	}

	/* (non-Javadoc)
	 * @see br.com.ctm.advogadope.rest.api.EntityResource#findAll(int, int)
	 */
	@Override
	@GET
	@Path("paginated/{firstResult}/{maxResults}")
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	@Wrapped(element = "usuarios")
	public List<Usuario> findAll(@PathParam("firstResult") int firstResult, @PathParam("maxResults") int maxResults)
			throws PersistenceException {
		return super.findAll(firstResult, maxResults);
	}

	/* (non-Javadoc)
	 * @see br.com.ctm.advogadope.rest.api.EntityResource#findByExample(br.com.framework.persistencia.model.BaseEntity)
	 */
	@Override
	@GET
	@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	@Wrapped(element = "usuarios")
	public List<Usuario> findByExample(Usuario entidade)
			throws PersistenceException {
		return super.findByExample(entidade);
	}

	/* (non-Javadoc)
	 * @see br.com.ctm.advogadope.rest.api.EntityResource#getRecordCount()
	 */
	@Override
	@GET
	@Path("count")
	@Produces(MediaType.TEXT_PLAIN)
	public Long getRecordCount() throws PersistenceException {
		return super.getRecordCount();
	}

	/* (non-Javadoc)
	 * @see br.com.ctm.advogadope.rest.api.EntityResource#insert(br.com.framework.persistencia.model.BaseEntity)
	 */
	@Override
	@POST
	@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public Response insert(Usuario entidade) throws NegocioException,
			PersistenceException {
		return super.insert(entidade);
	}

	/* (non-Javadoc)
	 * @see br.com.ctm.advogadope.rest.api.EntityResource#update(java.lang.Long, br.com.framework.persistencia.model.BaseEntity)
	 */
	@Override
	@PUT
	@Path("{id}")
	@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
	public Response update(@PathParam("id") Long id, Usuario entidade) throws NegocioException,
			PersistenceException {
		return super.update(id, entidade);
	}

	/* (non-Javadoc)
	 * @see br.com.ctm.advogadope.rest.api.EntityResource#remove(java.lang.Long)
	 */
	@Override
	@DELETE
	@Path("{id}")
	public Response remove(@PathParam("id") Long id) throws NegocioException,
			PersistenceException {
		return super.remove(id);
	}
}
